package com.mes.cloud.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * 登录token \  token redis相关操作
 *
 * @author: wxm
 * @date: 2019/5/6 15:26
 * @version: 1.0
 */
@Component
public class TokenUtil {

    /**
     * 生成token
     * @author: wxm
     * @date:   2019/5/6
     * @param:
     * @return:
     */
    public static String createToken(){
        return UUIDUtil.getUUID();
    }

    /**
     * 获取token 终端传递
     * @author: wxm
     * @date:   2019/5/6
     * @param:
     * @return:
     */
    public static String getToken(){
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        // 获取请求token
        String token = request.getParameter("token");
        return token;
    }
}
